using System;
using NUnit.Core;
using NUnit.Framework;
using Madason.MetaModel.Validation;

namespace Madason.MetaModel.DAO.Tests
{


	/// <summary>
	/// Summary description for TestEntity
	/// </summary>
	[TestFixture]
	public class TestEntity
	{
		[Test]
		public void TestEntityHasPrimaryKey()
		{
			Entity entity = new Entity();
			ValidationIssueList validationIssues = new ValidationIssueList();
			entity.Validate(validationIssues);
			Assert.IsTrue(validationIssues.ContainsMessage(Entity.ERROR_MISSING_PK), "Entity doesn't complain about PK");
		}

		[Test]
		public void TestEntityAssociationToNonEntity()
		{
			Model model = new Model();
			Entity entity = new Entity();
			entity.Id = "1";
			Class nonEntity = new Class();
			nonEntity.Id = "2";
			Association assoc = new Association();
			assoc.Class = entity;
			entity.Associations.Add(assoc);
			assoc.TargetClassId = nonEntity.Id;
			model.Classes.Add(entity);
			model.Classes.Add(nonEntity);

			ValidationIssueList validationIssues = new ValidationIssueList();
			entity.Validate(validationIssues);
			Assert.IsTrue(validationIssues.ContainsMessage(Entity.ERROR_WRONG_ASSOC_TARGET), "Entity doesn't complain wrong Association to non-entity");
		}
	}
}